Public Sub test_all_case()
    test_transMdTableTo2DArray
    test_trans2DArrToMdTableTxt
    test_transRangeToMdTableTxt
End Sub

' !!!会修改 sheet，暂时不参与完整测试
' 输出到指定 sheet，并忽略空行
Private Sub test_writeMdTableArrayToSheet_skipEmptyRow()
    Dim mdTable2DArr As Variant
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    mdTable2DArr = UtilMarkdown.transMdTableTo2DArray(txt)

    UtilMarkdown.writeMdTableArrayToSheet mdTable2DArr, ActiveSheet, needEmptyRow:=False
End Sub
' 输出到指定 sheet，并保留分割行
Private Sub test_writeMdTableArrayToSheet_withEmptyRow()
    Dim mdTable2DArr As Variant
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    mdTable2DArr = UtilMarkdown.transMdTableTo2DArray(txt)

    UtilMarkdown.writeMdTableArrayToSheet mdTable2DArr, ActiveSheet
End Sub

' 输出到指定 sheet，并忽略分割行
Private Sub test_transMdTableToSheet_skipSecondSplitRow()
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    UtilMarkdown.transMdTableToSheet txt, ActiveSheet, "c2", False
End Sub
' 输出到指定 sheet，并保留分割行
Private Sub test_transMdTableToSheet_withSecondSplitRow()
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    UtilMarkdown.transMdTableToSheet txt, ActiveSheet, "c2", False, False
End Sub

' 输出到当前的活动 sheet，并忽略分割行
Private Sub test_transMdTableToActiveSheet_skipSecondSplitRow()
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    UtilMarkdown.transMdTableToActiveSheet txt, "c2", False
End Sub
' 输出到当前的活动 sheet，并保留分割行
Private Sub test_transMdTableToActiveSheet_withSecondSplitRow()
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    UtilMarkdown.transMdTableToActiveSheet txt, "c2", False, False
End Sub

' 输出到新建的 sheet，并忽略分割行
Private Sub test_transMdTableToNewSheet_skipSecondSplitRow()
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    Dim newSheetName As String
    newSheetName = UtilMarkdown.transMdTableToNewSheet(txt, skipSecondSplitRow:=True)

    Debug.Print "newSheetName=" & newSheetName
End Sub
' 输出到新建的 sheet，并保留分割行
Private Sub test_transMdTableToNewSheet_withSecondSplitRow()
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    Dim newSheetName As String
    newSheetName = UtilMarkdown.transMdTableToNewSheet(txt, skipSecondSplitRow:=False)

    Debug.Print "newSheetName=" & newSheetName
End Sub

' ======================================================================
' 参与完成测试的方法
' ======================================================================
Private Sub test_transMdTableTo2DArray()
    ' ==================================================
    ' 1. 测试: 返回结果和 txt 中的项目内容、数量是否相同
    '          有分割行 + 不保留第二行的分割行
    ' ==================================================
    Dim txt As String
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "| a1 | a2 | a3 | a4 |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf

    Dim result As Variant
    result = UtilMarkdown.transMdTableTo2DArray(txt, skipSecondSplitRow := True)

    Debug.Assert Ubound(result) = 2
    Debug.Assert result(0)(0) = "title-a"
    Debug.Assert result(0)(1) = "title-b"
    Debug.Assert result(0)(2) = "title-c"
    Debug.Assert result(0)(3) = "title-d"
    Debug.Assert result(1)(0) = "a1"
    Debug.Assert result(1)(1) = "a2"
    Debug.Assert result(1)(2) = "a3"
    Debug.Assert result(1)(3) = "a4"
    Debug.Assert result(2)(0) = "b1"
    Debug.Assert result(2)(1) = "b2"
    Debug.Assert result(2)(2) = "b3"
    Debug.Assert result(2)(3) = "b4"

    ' ==================================================
    ' 2. 测试: 返回结果和 txt 中的项目内容、数量是否相同
    '          没有有分割行 + 保留第二行的分割行
    ' ==================================================
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| a1 | a2 | a3 | a4 |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf
    result = UtilMarkdown.transMdTableTo2DArray(txt, skipSecondSplitRow := True)

    Debug.Assert Ubound(result) = 2
    Debug.Assert result(0)(0) = "title-a"
    Debug.Assert result(0)(1) = "title-b"
    Debug.Assert result(0)(2) = "title-c"
    Debug.Assert result(0)(3) = "title-d"
    Debug.Assert result(1)(0) = "a1"
    Debug.Assert result(1)(1) = "a2"
    Debug.Assert result(1)(2) = "a3"
    Debug.Assert result(1)(3) = "a4"
    Debug.Assert result(2)(0) = "b1"
    Debug.Assert result(2)(1) = "b2"
    Debug.Assert result(2)(2) = "b3"
    Debug.Assert result(2)(3) = "b4"

    ' ==================================================
    ' 3. 测试: 返回结果和 txt 中的项目内容、数量是否相同
    '          存在分割行 + 保留第二行的分割行
    ' ==================================================
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "| a1 | a2 | a3 | a4 |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf
    result = UtilMarkdown.transMdTableTo2DArray(txt, skipSecondSplitRow := False)

    Debug.Assert Ubound(result) = 3
    Debug.Assert result(0)(0) = "title-a"
    Debug.Assert result(0)(1) = "title-b"
    Debug.Assert result(0)(2) = "title-c"
    Debug.Assert result(0)(3) = "title-d"
    Debug.Assert result(1)(0) = "-"
    Debug.Assert result(1)(1) = "-"
    Debug.Assert result(1)(2) = "-"
    Debug.Assert result(1)(3) = "-"
    Debug.Assert result(2)(0) = "a1"
    Debug.Assert result(2)(1) = "a2"
    Debug.Assert result(2)(2) = "a3"
    Debug.Assert result(2)(3) = "a4"
    Debug.Assert result(3)(0) = "b1"
    Debug.Assert result(3)(1) = "b2"
    Debug.Assert result(3)(2) = "b3"
    Debug.Assert result(3)(3) = "b4"

    ' ==================================================
    ' 4. 测试: 返回结果和 txt 中的项目内容、数量是否相同
    '          不存在分割行 + 保留第二行的分割行
    ' ==================================================
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| a1 | a2 | a3 | a4 |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf
    result = UtilMarkdown.transMdTableTo2DArray(txt, skipSecondSplitRow := False)

    Debug.Assert Ubound(result) = 2
    Debug.Assert result(0)(0) = "title-a"
    Debug.Assert result(0)(1) = "title-b"
    Debug.Assert result(0)(2) = "title-c"
    Debug.Assert result(0)(3) = "title-d"
    Debug.Assert result(1)(0) = "a1"
    Debug.Assert result(1)(1) = "a2"
    Debug.Assert result(1)(2) = "a3"
    Debug.Assert result(1)(3) = "a4"
    Debug.Assert result(2)(0) = "b1"
    Debug.Assert result(2)(1) = "b2"
    Debug.Assert result(2)(2) = "b3"
    Debug.Assert result(2)(3) = "b4"

    ' ==================================================
    ' 5. 测试: 返回结果和 txt 中的项目内容、数量是否相同
    '          存在分割行 + 不保留第二行的分割行
    '          测试默认参数值
    ' ==================================================
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "| a1 | a2 | a3 | a4 |" & vbCrLf & _
          "| b1 | b2 | b3 | b4 |" & vbCrLf
    result = UtilMarkdown.transMdTableTo2DArray(txt)

    Debug.Assert Ubound(result) = 2
    Debug.Assert result(0)(0) = "title-a"
    Debug.Assert result(0)(1) = "title-b"
    Debug.Assert result(0)(2) = "title-c"
    Debug.Assert result(0)(3) = "title-d"
    Debug.Assert result(1)(0) = "a1"
    Debug.Assert result(1)(1) = "a2"
    Debug.Assert result(1)(2) = "a3"
    Debug.Assert result(1)(3) = "a4"
    Debug.Assert result(2)(0) = "b1"
    Debug.Assert result(2)(1) = "b2"
    Debug.Assert result(2)(2) = "b3"
    Debug.Assert result(2)(3) = "b4"

    ' ========================================
    ' 6. 测试: 输入数据 = 空字符串
    ' ========================================
    result = UtilMarkdown.transMdTableTo2DArray("")
    Debug.Assert UBound(result) = -1

    ' ========================================
    ' 7. 测试: 输入数据的某一行 = 空
    ' ========================================
    txt = "| title-a | title-b | title-c | title-d |" & vbCrLf & _
          "| - | - | - | - |" & vbCrLf & _
          "|  |" & vbCrLf
    result = UtilMarkdown.transMdTableTo2DArray(txt, skipSecondSplitRow := False)
    Debug.Assert UBound(result) = 2
    Debug.Assert UBound(result(2)) = -1
End Sub

Private Sub test_trans2DArrToMdTableTxt()
    Dim data
    Dim result As String

    ' ========================================
    ' 1. 测试: 第二行不是分割行 + 需要保留空行 + 换行符为 vbCrLf
    ' ========================================
    data = Array( _
        Array("title1-a", "title1-b", "title1-c"), _
        Array("a1", "b1", "c1"), _
        Array(), _
        Array("a2", "b2", "c2") _
    )
    result = UtilMarkdown.trans2DArrToMdTableTxt(data, secondIsSplitRow:=False, needEmptyRow:=True)
    Debug.Assert result= _
      "| title1-a | title1-b | title1-c |" & vbCrLf & _
      "| - | - | - |" & vbCrLf & _
      "| a1 | b1 | c1 |" & vbCrLf & _
      "| | | |" & vbCrLf & _
      "| a2 | b2 | c2 |"

    ' ========================================
    ' 2. 测试: 第二行不是分割行 + 需要保留空行 + 换行符为 vbLf
    ' ========================================
    data = Array( _
        Array("title1-a", "title1-b", "title1-c"), _
        Array("a1", "b1", "c1"), _
        Array(), _
        Array("a2", "b2", "c2") _
    )
    result = UtilMarkdown.trans2DArrToMdTableTxt(data, secondIsSplitRow:=False, needEmptyRow:=True, lineBreak:=vbLf)
    Debug.Assert result= _
      "| title1-a | title1-b | title1-c |" & vbLf & _
      "| - | - | - |" & vbLf & _
      "| a1 | b1 | c1 |" & vbLf & _
      "| | | |" & vbLf & _
      "| a2 | b2 | c2 |"

    ' ========================================
    ' 3. 测试: 第二行是分割行 + 需要保留空行 + 换行符为 vbCrLf
    ' ========================================
    data = Array( _
        Array("title1-a", "title1-b", "title1-c"), _
        Array("--", "--", "--"), _
        Array("a1", "b1", "c1"), _
        Array(), _
        Array("a2", "b2", "c2") _
    )
    result = UtilMarkdown.trans2DArrToMdTableTxt(data, secondIsSplitRow:=True, needEmptyRow:=True)
    Debug.Assert result= _
      "| title1-a | title1-b | title1-c |" & vbCrLf & _
      "| -- | -- | -- |" & vbCrLf & _
      "| a1 | b1 | c1 |" & vbCrLf & _
      "| | | |" & vbCrLf & _
      "| a2 | b2 | c2 |"

    ' ========================================
    ' 4. 测试: 第二行不是分割行 + 不需要保留空行 + 换行符为 vbCrLf
    ' ========================================
    data = Array( _
        Array("title1-a", "title1-b", "title1-c"), _
        Array("a1", "b1", "c1"), _
        Array(), _
        Array("a2", "b2", "c2") _
    )
    result = UtilMarkdown.trans2DArrToMdTableTxt(data, secondIsSplitRow:=False, needEmptyRow:=False)
    Debug.Assert result= _
      "| title1-a | title1-b | title1-c |" & vbCrLf & _
      "| - | - | - |" & vbCrLf & _
      "| a1 | b1 | c1 |" & vbCrLf & _
      "| a2 | b2 | c2 |"
End Sub

Private Sub test_transRangeToMdTableTxt()
    ActiveSheet.Range("C2") = "title-1"
    ActiveSheet.Range("D2") = "title-2"
    ActiveSheet.Range("E2") = "title-3"
    ActiveSheet.Range("C3") = "a1"
    ActiveSheet.Range("D3") = "b1"
    ActiveSheet.Range("E3") = "c1"
    ActiveSheet.Range("C4") = "a2"
    ActiveSheet.Range("D4") = "b2"
    ActiveSheet.Range("E4") = "c2"

    Dim result As String
    ' ========================================
    ' 1. 测试: 第二行不是分割行 + 换行符为 vbCrLf
    ' ========================================
    result = UtilMarkdown.transRangeToMdTableTxt(ActiveSheet.Range("C2:E4"), secondIsSplitRow:=False, lineBreak:=vbCrLf)
    Debug.Assert result= _
      "| title-1 | title-2 | title-3 |" & vbCrLf & _
      "| - | - | - |" & vbCrLf & _
      "| a1 | b1 | c1 |" & vbCrLf & _
      "| a2 | b2 | c2 |"

    ' ========================================
    ' 2. 测试: 第二行不是分割行 + 换行符为 vbLf
    ' ========================================
    result = UtilMarkdown.transRangeToMdTableTxt(ActiveSheet.Range("C2:E4"), secondIsSplitRow:=False, lineBreak:=vbLf)
    Debug.Assert result= _
      "| title-1 | title-2 | title-3 |" & vbLf & _
      "| - | - | - |" & vbLf & _
      "| a1 | b1 | c1 |" & vbLf & _
      "| a2 | b2 | c2 |"
      
    ' ========================================
    ' 3. 测试: 第二行是分割行 + 换行符为 vbCrLf
    ' ========================================
    ActiveSheet.Range("C2") = "title-1"
    ActiveSheet.Range("D2") = "title-2"
    ActiveSheet.Range("E2") = "title-3"
    ActiveSheet.Range("C3") = "---"
    ActiveSheet.Range("D3") = "---"
    ActiveSheet.Range("E3") = "---"
    ActiveSheet.Range("C4") = "a1"
    ActiveSheet.Range("D4") = "b1"
    ActiveSheet.Range("E4") = "c1"
    ActiveSheet.Range("C5") = "a2"
    ActiveSheet.Range("D5") = "b2"
    ActiveSheet.Range("E5") = "c2"
    result = UtilMarkdown.transRangeToMdTableTxt(ActiveSheet.Range("C2:E5"), secondIsSplitRow:=True, lineBreak:=vbCrLf)
    Debug.Assert result= _
      "| title-1 | title-2 | title-3 |" & vbCrLf & _
      "| --- | --- | --- |" & vbCrLf & _
      "| a1 | b1 | c1 |" & vbCrLf & _
      "| a2 | b2 | c2 |"
      
End Sub
